from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import Select
class Grap:
    def __init__(self):
        # 设置驱动的路径,这是 selenium4之后的新写法
        self.service = Service(executable_path=r"C:\Program Files\Google\Chrome\Application\chromedriver.exe")
        # 实例化浏览器对象
        self.driver = webdriver.Chrome(service=self.service)

    # ----- # 下拉框 -----
    def getchoose(self):
        self.driver.get(r'D:\lunwen\scrapy\auto\choose.html')
        # 找到下拉框元素
        element = self.driver.find_element(By.TAG_NAME,'select')
        select = Select(element)
        # 选择下拉框中第2个选项
        select.select_by_index(1)   
        time.sleep(5) 
if __name__ == '__main__':
    g = Grap()
    g.getchoose()


